home *** CD-ROM | disk | FTP | other *** search
/ Quick PC 61 / Quick PC 61.iso / I386 / SASETUP.MSI / F77693_Text_MultiLog_download.asp < prev    next >
Encoding:
Text File  |  2003-02-21  |  6.4 KB  |  186 lines

  1. <%@ Language=VBScript        %>
  2. <%    Option Explicit            %>
  3. <%    Response.Buffer = True
  4.     '-------------------------------------------------------------------------
  5.     ' Text_log_download.asp: to download the log files of type text
  6.     '
  7.     ' NOTE: This is a customized page written to take care of the "Downloading"
  8.     ' of the log(text) files. 
  9.     ' This is not the types of the pages(area, property, etc) of the framework.
  10.     ' Hence, the events applicable to those is not used  here.
  11.     '
  12.     ' Copyright (c) Microsoft Corporation.  All rights reserved. 
  13.     '-------------------------------------------------------------------------
  14.     Call SAI_EnablePageCaching(TRUE)    
  15. %>
  16.     <!-- #include virtual="/admin/inc_framework.asp" --> 
  17.     <!-- #include file="loc_Log.asp" -->
  18.     <!-- #include file="inc_Log.asp" -->
  19. <%
  20.     '-------------------------------------------------------------------------
  21.     ' Form Variables
  22.     '-------------------------------------------------------------------------
  23.     Dim F_strFilePath        'Name of the file to be downloaded     'Example: "C:\SFU\Log\"
  24.     Dim F_strFileName        'File name to be prompted for download    - Example: nfssvr.txt
  25.     
  26.     '-------------------------------------------------------------------------
  27.     ' Global Variables
  28.     '-------------------------------------------------------------------------
  29.     
  30.     Dim G_strBrowserVersion    'variable for getting the client config
  31.     Dim G_nBrowserVersion    'variable to locate the positin occurence of Browser version string
  32.     Dim blnFlagIE 
  33.     
  34.     dim rc
  35.     dim page
  36.     dim L_LOGS_TEXT
  37.     
  38.     L_LOGS_TEXT = "Logs"
  39.  
  40.     If SA_IsIE = True Then
  41.         blnFlagIE = True 
  42.     End If
  43.     
  44.     Call SA_CreatePage(L_LOGS_TEXT,"", PT_PAGELET, page)
  45.     Call SA_ShowPage(page)
  46.  
  47.     
  48.      '---------------------------------------------------------------------
  49.     ' Function name:    OnInitPage
  50.     ' Description:        Called to signal first time processing for this page. 
  51.     ' Input Variables:    PageIn and EventArg
  52.     ' Output Variables:    PageIn and EventArg
  53.     ' Return Values:    TRUE to indicate initialization was successful. FALSE to indicate
  54.     '                    errors. Returning FALSE will cause the page to be abandoned.
  55.     ' Global Variables: None
  56.     ' Called to signal first time processing for this page. 
  57.     '---------------------------------------------------------------------
  58.     Public Function OnInitPage(ByRef Page, ByRef Reserved)
  59.         OnInitPage = TRUE
  60.     End Function
  61.  
  62.     '---------------------------------------------------------------------
  63.     ' Function name:    OnServePageletPage
  64.     ' Description:        Called when the page needs to be served. 
  65.     ' Input Variables:    PageIn, Reserved
  66.     ' Output Variables:    PageIn, Reserved
  67.     ' Return Values:    TRUE to indicate no problems occured. FALSE to indicate errors.
  68.     '                    Returning FALSE will cause the page to be abandoned.
  69.     ' Global Variables: F_*
  70.     'Called when the page needs to be served. Use this method to serve content.
  71.     '---------------------------------------------------------------------
  72.     Public Function OnServePageletPage(ByRef Page, ByRef Reserved)
  73.         OnServePageletPage = TRUE
  74.         
  75.         Call SA_ServeDefaultClientScript()
  76.         
  77.         'frame work variables used for getting the selected ots entries
  78.         Dim x
  79.         Dim itemCount
  80.         Dim itemKey
  81.         
  82.         'File name(along with the path) that is obtained from earlier form
  83.         F_strFilePath  = Request.QueryString("FilePath")
  84.             
  85.         ' get the file to be deleted as Query String from previous page
  86.             
  87.         If    Instr(1,Request.QueryString(),"Single",1) then
  88.             F_strFileName = Request.QueryString("Pkey")
  89.         Else
  90.             ' Show a list of the items selected
  91.             itemCount = OTS_GetTableSelectionCount("")            
  92.             For x = 1 to itemCount
  93.                 If ( OTS_GetTableSelection("", x, itemKey) ) Then
  94.                     F_strFileName = itemKey    
  95.                 End If
  96.             Next
  97.         End if    
  98.         
  99.         'Check if the file is existing
  100.         If Not (isFileExisting(F_strFilePath & "\" & F_strFileName)) Then
  101.             
  102.             'File is moved/deleted/renamed. Display failure page
  103.             Call SA_ServeFailurePage (L_LOGFILE_NOTFOUND_ERRORMESSAGE) 
  104.             
  105.         End If    
  106.             
  107.         'Call to output the log file
  108.         Call DispalyFileContent(F_strFilePath,F_strFileName)
  109.  
  110.     End Function
  111.  
  112.     '---------------------------------------------------------------------
  113.     ' Function name:    DispalyFileContent
  114.     ' Description:        To Read and Output the contents of the file
  115.     ' Input Variables:    The file to be read and displayed
  116.     ' Output Variables:    None
  117.     ' Return Values:    None
  118.     ' Global Variables: None
  119.     'Called to read the total content of the file and output it.
  120.     'For Netscape the headers are not added location.href is used 
  121.     'Due to the headers, the "download" dialog appears
  122.     '---------------------------------------------------------------------
  123.     Sub DispalyFileContent(strFilePath , strFileName)
  124.         Err.clear
  125.         On Error Resume Next
  126.         
  127.         Dim objFSO     ' the File System Object
  128.         Dim objFile    ' the File to be read
  129.         Dim strTemp,strTotalFileName
  130.         Dim strLogPath
  131.         Dim strDownloadFile
  132.                 
  133.         const TempDir = "TempFiles"    ' A Temporary directory in web directory
  134.         const LogDir = "LogFiles" ' A logs directory in Temporary directory
  135.         const strON    = "On"
  136.         
  137.         strTotalFileName=strFilePath & "\" & strFileName
  138.         
  139.         Set objFSO = CreateObject("Scripting.FileSystemObject")
  140.         
  141.          
  142.         If blnFlagIE = True then
  143.         
  144.             Set objFile = objFSO.OpenTextFile(strTotalFileName, 1, False)
  145.             'Read the contents of the file
  146.             If not objFile.AtEndOfStream Then strTemp = objFile.readall End IF
  147.  
  148.             ' Add headers required for download
  149.             Response.AddHeader "Content-Type", "text/plain"
  150.             Response.AddHeader "Content-Disposition", "attachment; filename=" & F_strFileName
  151.  
  152.             'Clear any previous buffered output
  153.             Response.Clear
  154.  
  155.             'Output it for download
  156.             Response.Write strTemp
  157.         
  158.             objFile.Close
  159.             Response.End 
  160.         Else    
  161.             strLogPath = GetLogsDirectoryPath(objFSO)
  162.             
  163.             If objFSO.FileExists(strLogPath& "\" &strFileName) then
  164.                 objFSO.DeleteFile strLogPath& "\" &strFileName,True
  165.             End If
  166.             
  167.             ' Copying from log's original directory to web root
  168.             If objFSO.FileExists(strTotalFileName) Then
  169.                 objFSO.CopyFile strTotalFileName, strLogPath& "\" ,True
  170.             End If
  171.             
  172.             'Clean up
  173.             Set objFile = Nothing
  174.             Set objFSO  = Nothing
  175.             
  176.             strDownloadFile = SA_GetNewHostURLBase(SA_DEFAULT, SAI_GetSecurePort(), True, SA_DEFAULT)
  177.             strDownloadFile = strDownloadFile & TempDir &"/" &LogDir &"/" & strFileName
  178.             Call SA_TraceOut(SA_GetScriptFileName, "Redirect to URL: " & strDownloadFile)
  179.             
  180.             Response.Redirect strDownloadFile
  181.         End If
  182.  
  183.     End Sub    
  184.     
  185. %>
  186.